import React from 'react';
import {Table} from 'antd'
import moment from 'moment'
import {connect} from 'dva'
import { load } from 'react-cookies';
class TableData extends React.Component {
    
    render(){
        const {loading}=this.props;
        const {exerciseData}=this.props.exercise;
        const columns = [       
            {
              title: '日期',
              dataIndex: 'start',
              width:'25%',
              render:text=>moment(text).format('YYYY-MM-DD')
            },    
            {
              title: '里程',
              dataIndex: 'mileage',
              width:'25%',
              render:text=>text+'Km'
            },    
            {
              title: '时间',
              dataIndex: 'time',
              width:'25%',
              render:text=>text+'Min'
            },    
            {
              title: '地点',
              dataIndex: 'place',
            }
        ]
        return(
            <div>
                <Table 
                    dataSource={exerciseData}
                    columns={columns}
                    rowKey='_id'
                    loading={loading}
                    pagination={{
                        total:exerciseData.length,
                        showTotal:total=>`共${total}条数据`,
                        showSizeChanger:true,
                        size:'small',
                        pageSizeOptions:['10','100','1000']
                    }}
                    scroll={{y:'70vh'}}
                />

            </div>
        )
    }
}

export default connect(({ exercise, loading }) => ({ exercise, loading: loading.effects['exercise/getExerciseData'] }))(
    TableData,
  );